import 'package:flutter/material.dart';
import 'package:flutter_house_manager/pages/Home/houseList.dart';
import 'package:flutter_house_manager/pages/Login/index.dart';
import 'package:flutter_house_manager/pages/NoticeDetail/index.dart';
import 'package:flutter_house_manager/pages/Profile/index.dart';
import 'package:flutter_house_manager/pages/TabsPage/index.dart';
import 'package:flutter_house_manager/utils/TokenManager.dart';

void main() {
  // runApp进行启动应用
  // 启动app 只放一个居中文本 内容是测试
  runApp(MaterialApp(
    title: '房屋管理系统',
    initialRoute: '/', // 第一个页面是哪个
    // 配置路由列表
    routes: {
      "/": (context) => const TabsPage(),
      "/noticeDetail": (context) => const NoticeDetail(),
      "/login": (context) => const LoginPage(),
      // "/profile": (context) => const ProfilePage(),
    },
    onGenerateRoute: (settings) {
      String token = tokenManager.getToken();
      if (token.isEmpty) {
        return MaterialPageRoute(
          builder: (context) => LoginPage(
            toName: settings.name,
          ),
        );
      }
      if (settings.name == '/profile') {
        return MaterialPageRoute(
          builder: (context) => const ProfilePage(),
        );
      }
      if(settings.name=='/house_list'){
        return MaterialPageRoute(
          builder: (context) => const HouseList(),
        );
      }
      return null;
    },
  ));
}
